// createRouter: 函数用来生成路由实例对象
// createWebHistory: 函数 用来生成history模式的路由

import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/views/Layout'
import Login from '@/views/Login'
import Home from '@/views/Home'
import Category from '@/views/Category'
import Goods from '@/views/Goods'
import Cart from '@/views/Cart'
import Settle from '@/views/Settle'
import Pay from '@/views/Pay'

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '', // 路由置空的时候会作为一级路由默认渲染的二级路由
        component: Home
      },
      {
        path: 'category/:id',
        component: Category
      },
      {
        path: '/goods/:id',
        component: Goods
      },
      {
        path: 'cart',
        component: Cart
      },
      {
        path: 'settle',
        component: Settle
      },
      {
        name: 'pay',
        path: 'pay/:id',
        component: Pay
      }
    ]
  },
  {
    path: '/login',
    component: Login
  }
]

// 生成路由实例对象
const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

// 导出

export default router
